<%@ page language="java" import="java.util.*,bookstore.database.pojo.*"
	pageEncoding="utf-8"%>
<%
	Map<String, Map<String, Integer>> cart = (Map<String, Map<String, Integer>>) 
	session.getAttribute("cart");
	//Map中参数说明map<isbn,map<卖家id,数量>>
	//提供此函数获取卖家所卖图书的售价String price = new SaleTableDAO().findByIsbnAndSelId(isbn,seller_id);
	//参数isbn为图书isbn号,seller_id为卖家id
	String totalPrice = "0.0";
	if(cart != null){
		totalPrice = ((Double)session.getAttribute("totalprice")).toString();
	}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>

		<title>我mai 显示购物车</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">

		<link rel="stylesheet" type="text/css" href="/css/my.css">
		<script type="text/javascript">
function returnIndex() {

	window.open("index.jsp", "_self");
}
function makeOrder() {

	window.open("orderSubmit.jsp", "_self");
}

function removeAll() {

	window.open("removeAll.do", "_self");
}
</script>

	</head>

	<body>
	
		<table width="80%" border="0" align="center">
			<tr>
				<td width="99%" colspan="2">
					<div align="center"><jsp:include flush="true" page="head.jsp"></jsp:include></div>
				</td>
			</tr>
			
			<tr>
				<td colspan="2" class="style1">
					我的购物车<img src="img/cart.jpg" width="34" height="33" />
					<hr />
				</td>
			</tr>
			<%if (cart!=null && cart.size() != 0){%>
			<tr>
				<td colspan="2">
					<table width="100%" border="1" bordercolor="#00FFFF">
						<tr>
							<td bordercolor="#00FFFF">
								<div align="center">
									书名
								</div>
							</td>
							<td bordercolor="#00FFFF">
								<div align="center">
									卖家
								</div>
							</td>
							<td bordercolor="#00FFFF">
								<div align="center">
									售价
								</div>
							</td>
							<td bordercolor="#00FFFF">
								<div align="center">
									数量
								</div>
							</td>
							<td bordercolor="#00FFFF">
								<div align="center">
									操作
								</div>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<%
				Iterator it = cart.keySet().iterator();
				while (it.hasNext()) {
					String isbn = (String) it.next();
					Map<String, Integer> seller = cart.get(isbn);
					Iterator it2 = seller.keySet().iterator();
					while (it2.hasNext()) {
						String id = (String) it2.next();
						//int int_id = Integer.parseInt(id);
						java.math.BigDecimal b_id = new java.math.BigDecimal(id);
						//获取数量
						int number = seller.get(id);
						//获取价格
						String price = new SaleTableDAO().findByIsbnAndSelId(isbn,id);
						//获取书名
						Book book = new BookDAO().findById(isbn);
						String bookName = book.getBname();
						//获取卖家用户名
						Seller b_seller = new SellerDAO().findById(b_id);
						Customer customer = b_seller.getCustomer();
						String customer_name = customer.getCustomerName();
						String url = "removeBook.do?removeisbn="+ isbn +"&sellerid="+ id;
			
			%>
			<tr>
				<td colspan="2">
					<table width="100%" border="1" bordercolor="#00FFFF">
						<tr>
							<td width="20%" bordercolor="#00FFFF">
								<div align="center"><%=bookName%></div>
							</td>
							<td width="20%" bordercolor="#00FFFF">
								<div align="center"><%=customer_name%></div>
							</td>
							<td width="20%" bordercolor="#00FFFF">
								<div align="center">￥<%=price%></div>
							</td>
							<td width="20%" bordercolor="#00FFFF">
								<div align="center"><%=number%></div>
							</td>
							<td width="20%" bordercolor="#00FFFF">
								<div align="center">
									<a href=<%=url %>>删除</a>
								</div>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<%
				}
				}
			%>

			<tr>
				<td colspan="2">
					&nbsp;
					<div align="center">
						<input type="submit" name="Submit" value="删除全部" onclick='removeAll()'/>
					</div>
					<hr />
				</td>
			</tr>
			<tr>
				<td width="50%" class="style3">
					小计：￥<%=totalPrice %>
				</td>
				<td width="50%">
					<div align="right">
						<input type="submit" name="Submit3" value="返回继续购物"
							onclick='returnIndex()'; />
						<input type="submit" name="Submit2" value="进入结算中心" 
						onclick='makeOrder();'
						/>
					</div>
				</td>
			</tr><%}else{ %>
			<tr>
			<td>
			您的购物车没有商品。			
			</td>
			</tr>
			<%} %>
			<tr>
				<td colspan="2">
					<hr />
					&nbsp;
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<div align="center"><jsp:include flush="true" page="tail.jsp"></jsp:include></div>
				</td>
			</tr>
		</table>
	</body>
</html>
